#ifndef _BASEWIDGET__
#define _BASEWIDGET__ -1

#include once "mud-gui/widgetIDs.bi"
#include once "mud-gui/event.bi"
#include once "mud-gui/gclass.bi"
#include once "fbgfx.bi"

namespace ui

enum layout_t explicit
	canHaveLayout 'can layout children
	noLayout 'not supposed to have children
end enum

type BaseWidgetFwd as BaseWidget

type BaseWidget_list
	_data as BaseWidgetFwd ptr
	_next as BaseWidget_list ptr
	declare destructor( )
end type

type signal_callback as function( byval _ref as BaseWidgetFwd ptr, byval e_ as _GUI_EVENT_ ptr ) as integer

type Signals
	clicked as signal_callback
	mouseover as signal_callback
	mousedown as signal_callback
	mousewheel as signal_callback
	keystroke as signal_callback
	destroy as signal_callback
	timerExpire as signal_callback
	resize as signal_callback
	repaint as signal_callback
	usersignal as signal_callback
end type

type Signal_list
	_sig as Signals
	_next as Signal_list ptr
	declare destructor( )
end type

type BaseWidget FIELD=1
	'Private
	id as widgetID
	cl as layout_t
	x as integer
	y as integer
	width as integer
	height as integer
	minwidth as integer
	minheight as integer
	buffer as fb.IMAGE ptr
	parent as BaseWidget ptr
	parent_data as any ptr
	children as BaseWidget_list ptr
	_signals as Signal_list ptr

	'Public
	status as integer
	user_data as any ptr

	'signals 
	DEF_SBPROPERTY( clicked, signal_callback )
	DEF_SBPROPERTY( mouseover, signal_callback )
	DEF_SBPROPERTY( mousedown, signal_callback )
	DEF_SBPROPERTY( mousewheel, signal_callback )
	DEF_SBPROPERTY( keystroke, signal_callback )
	DEF_SBPROPERTY( destroy, signal_callback )
	DEF_SBPROPERTY( timerExpire, signal_callback )
	DEF_SBPROPERTY( resize, signal_callback )
	DEF_SBPROPERTY( repaint, signal_callback )
	DEF_SBPROPERTY( usersignal, signal_callback )

	'Private
	declare sub addRemoveSignal( byval func as signal_callback, byval s as GEVENT )
	declare function process_signals( byval _ref as BaseWidget ptr, byval e_ as _GUI_EVENT_ ptr ) as integer
	declare function process_event( byval _ref as BaseWidget ptr, _
				byval e_ as _GUI_EVENT_ ptr ) as integer
	declare destructor()
	
	'Public
	declare sub addChild( byval _child_ as BaseWidget ptr )
	declare function hasChild( byval _child_ as BaseWidget ptr ) as integer
	declare sub deleteChild( byval _child_ as BaseWidget ptr )

end type

end namespace
#endif
